<?php
/**
 * Requirement entity
 */
namespace BWL\webshopBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="BWL\webshopBundle\Repository\RequirementRepository")
 * @ORM\Table(name="requirement",uniqueConstraints={
 * @ORM\UniqueConstraint(name="item_date_idx", columns={"item_id", "date"})})
 * @ORM\HasLifecycleCallbacks()
 */
class Requirement
{
  /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;

  /**
   * @ORM\ManyToOne(targetEntity="Item", inversedBy="requirements")
   * @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=false)
   */
  protected $item;

  /**
   * @ORM\OneToMany(targetEntity="RequirementDerivation", mappedBy="requirement")
   * @ORM\OrderBy({"created" = "ASC"})
   */
  protected $requirement_derivations;

  /**
   * @ORM\OneToMany(targetEntity="RequirementFulfilment", mappedBy="requirement")
   * @ORM\OrderBy({"created" = "ASC"})
   */
  protected $requirement_fulfilments;

  /**
   * @ORM\Column(type="datetime")
   */
  protected $date;

  /**
   * @ORM\Column(type="integer")
   */
  protected $amount;

  /**
   * @ORM\Column(type="datetime")
   */
  protected $created;

  /**
   * @ORM\Column(type="datetime")
   */
  protected $updated;

  /**
   * Constructor
   * Sets default values
   */
  public function __construct() {
    $this->setAmount(0);
    $this->assignments = new ArrayCollection();
    $this->setCreated(new \DateTime());
    $this->setUpdated(new \DateTime());
  }

  /**
   * @ORM\PreUpdate
   */
  public function setUpdatedValue() {
    $this->setUpdated(new \DateTime());
  }

  public function getAmount() {
    return $this->amount;
  }

  public function getAssignments() {
    return $this->assignments;
  }

  public function getItem() {
    return $this->item;
  }

  public function getCreated() {
    return $this->created;
  }

  public function getDate() {
    return $this->date;
  }

  public function getId() {
    return $this->id;
  }

  public function getUpdated() {
    return $this->updated;
  }

  public function setAmount($amount) {
    $this->amount = $amount;
    return $this;
  }

  public function setItem($item) {
    $this->item = $item;
    return $this;
  }

  public function setAssignments($assignments) {
    $this->assignments = $assignments;
    return $this;
  }

  public function setCreated($created) {
    $this->created = $created;
    return $this;
  }

  public function setDate($date) {
    $this->date = $date;
    return $this;
  }

  public function setUpdated($updated) {
    $this->updated = $updated;
    return $this;
  }

}